package designpattern.singleton;

import java.util.HashMap;
import java.util.Map;

public class RegisterSingleton {
	protected RegisterSingleton(){} 
	
	private static Map<String, RegisterSingleton> map = new HashMap<String,RegisterSingleton>();
	static{
		RegisterSingleton singleton = new RegisterSingleton();
		map.put(singleton.getClass().getName(), singleton);
	}
	
	public synchronized static RegisterSingleton getInstance(String name){
		if(map.containsKey(name)){
		}else{
			try {
				map.put(name, (RegisterSingleton)Class.forName(name).newInstance());
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		return (RegisterSingleton)map.get(name);
	}
}
